﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using System.Data.OracleClient;

namespace GatewayInspect.Modules
{
    public partial class AQGZJLModule : BaseModule
    {
        public AQGZJLModule()
        {
            InitializeComponent();
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            foreach (ToolStripItem item in this.tsMain.Items)
            {
                if (item != tsBtnRefresh && item != tsBtnClose && item != toolStripSeparator3)
                {
                    item.Visible = false;
                }
            }
        }

        protected override void OnInit()
        {
            base.OnInit();
            dtpEnd.Value = DateTime.Now;
            dtpBegin.Value = DateTime.Now.Date;

            BeginRead();//启动身份证读卡设备开始读卡 
        }

        protected override void OnLoadModule()
        {
            base.OnLoadModule();

            string strSql = "select * from T_SAFETY_INFORM where ORGCODE = '" + Session.CurrentOrgCode + "' and INFORMTIME >= :beginTime and INFORMTIME <= :endTime";
            if (!string.IsNullOrWhiteSpace(tbxDriverID.Text))
            {
                strSql += " and DRIVERID like '%" + tbxDriverID.Text + "%'";
            }
            strSql += " order by INFORMTIME desc";
            DataTable dtCYJL = DataAccess.ExecuteDataTable(strSql, new OracleParameter(":beginTime", dtpBegin.Value), new OracleParameter(":endTime", dtpEnd.Value));

            this.cdgvGZJL.AutoGenerateColumns = false;
            this.cdgvGZJL.DataSource = dtCYJL;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            OnLoadModule();
        }

        #region 读身份证

        private IDCradReader reader = null;

        protected override void OnModuleDestroyed()
        {
            base.OnModuleDestroyed();
            if (reader != null)
            {
                reader.AfterReadInfo -= new IDCradReader.AfterReadInfoHandler(reader_AfterReadInfo);
                reader.CheckHandler();//检查是否还有其他对象读卡
            }
        }

        private void BeginRead()
        {
            if (reader == null)
            {
                reader = IDCradReader.GetInstance();
                reader.AfterReadInfo += new IDCradReader.AfterReadInfoHandler(reader_AfterReadInfo);
            }
            reader.BeginRead();
        }

        private void reader_AfterReadInfo(CardInfo info)
        {
            if (IsActive && info != null)
            {
                this.tbxDriverID.Text = info.CardNo;
            }
        }

        #endregion

       
    }
}
